package com.jjyu.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jjyu.entity.FavoriteRestaurant;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface FavoriteRestaurantMapper extends BaseMapper<FavoriteRestaurant> {

    // 根据用户ID查找收藏的餐馆
    @Select("SELECT * FROM favorite_restaurants WHERE user_id = #{userId}")
    List<FavoriteRestaurant> findByUserId(Integer userId);

    // 新增商品收藏
    @Insert("INSERT INTO favorite_restaurants(user_id, restaurant_id, created_at, updated_at) " +
            "VALUES(#{userId}, #{restaurantId}, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)")
    int addFavoriteRestaurant(FavoriteRestaurant favoriteRestaurant);

    // 删除商品收藏
    @Delete("DELETE FROM favorite_restaurants WHERE favorite_id = #{favoriteId}")
    int deleteFavoriteRestaurant(Integer favoriteId);

    // 修改商品收藏（例如，修改收藏的餐馆ID）
    @Update("UPDATE favorite_restaurants SET restaurant_id = #{restaurantId}, updated_at = CURRENT_TIMESTAMP " +
            "WHERE favorite_id = #{favoriteId}")
    int updateFavoriteRestaurant(FavoriteRestaurant favoriteRestaurant);
}

